//
//  YunCangViewCellCollectionViewCell.swift
//  Wmsmobile
//
//  Created by Nick xu on 16/7/20.
//  Copyright © 2016年 hddden. All rights reserved.
//

import UIKit

class YunCangViewCellCollectionViewCell: UICollectionViewCell {
    
    var model:YunCangModel?{
        
        didSet{
            self.titleLabel?.text = model?.FCAPTION
            self.titleLabel?.textColor = UIColor.hexStringToUIColor("#3333333")
            if let imagename = model?.FCLASSNAME?.lowercased() {
                self.icon.image = UIImage(named: imagename)
            }else{
                self.icon.image = nil
            }
            
        }
    }
    
       override init(frame: CGRect) {
//        if userInfo?.fontLevel == .large {
            super.init(frame: frame)
            self.backgroundColor = UIColor.white
            let view = UIView(frame: self.bounds)
            self.selectedBackgroundView = view
            view.backgroundColor = UIColor.hexStringToUIColor("#dddddd")
            //给label布局
            self.contentView.addSubview(titleLabel!)
            titleLabel?.snp.makeConstraints({ (make) in
                make.centerX.equalTo(self.contentView)
                make.centerY.equalTo(self).offset(self.width / 4)
            })
            //布局imageview
            self.contentView.addSubview(icon)
            icon.snp.makeConstraints { (make) in
                make.centerY.equalTo(self.contentView).offset(-self.width / 8 - (WMSFonts["mainMenuCell"]!)[userInfo!.fontLevel.rawValue] / 4)
                make.centerX.equalTo(self.contentView)
            }

//        }else{
//            super.init(frame: frame)
//            self.backgroundColor = UIColor.whiteColor()
//            let view = UIView(frame: self.bounds)
//            self.selectedBackgroundView = view
//            view.backgroundColor = UIColor.hexStringToUIColor("#dddddd")
//            //布局imageview
//        self.contentView.addSubview(icon)
//        icon.snp.makeConstraints { (make) in
//            make.top.equalTo(self.contentView).offset(KscreenWidth / 20+5)
////            make.bottom.equalTo(self.snp.centerY)
//            make.centerX.equalTo(self.contentView)
//        }
//        //给label布局
//        self.contentView.addSubview(titleLabel!)
//        titleLabel?.snp.makeConstraints(closure: { (make) in
//            make.centerX.equalTo(self.contentView)
////            make.top.equalTo(self.icon.snp.bottom).offset(6)
////            make.top.equalTo(self.snp.centerY).offset(20)
//            make.bottom.equalTo(self).offset(-KscreenWidth / 20+5)
////            make.width.lessThanOrEqualTo(self.contentView.width)
//        })
//        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var titleLabel:UILabel? = {
        let lb = UILabel()
        lb.numberOfLines = 2
        let fontDict = WMSFonts["mainMenuCell"]!
        lb.font = UIFont.systemFont(ofSize: fontDict[userInfo!.fontLevel.rawValue])
        lb.textColor = UIColor.hexStringToUIColor("#111111")
//        lb.backgroundColor = UIColor.redColor()
        return lb
    }()
    lazy fileprivate var icon:UIImageView = {
        let  temp = UIImageView(image: UIImage(named: "\(self.model?.FGID)"))
        return temp
    }()

    
}
